<?php

class m_rights_actions_block_ListRolesAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$rightsService = m_rights_services_RightsService::getInstance();
		$modules = $rightsService->getAllModulesName();
		$group = $this->getDocumentProvider()->getByUniqueId($this->getRequestParameter("docId"));
				
		$titleRights = array();
		$tabRights = array();
		$rightInfo = array();
		
		$inheritRights = $rightsService->getInheritRightsForGroup($group);

		foreach($modules as $module)
		{
			$titleRights = $rightsService->readTitleRightsFromModule($module);
			$rights = $rightsService->readRightsFromModule($module);
			$authorized = $rightsService->readRightsFromModuleForGroup($module, $group);
			
			foreach($rights as $right)
			{
				$rightInfo['name'] = $module."_".$right['name'];
				$rightInfo['label'] = $right['label'];
				$rightInfo['module'] = $module;
				$rightInfo['access'] = $authorized[$right['name']];
				$rightInfo['inherit'] = in_array($rightInfo['name'],$inheritRights) ? true : false;
				$tabRights[$titleRights][] = $rightInfo;
			}
		}

		$values["isSuperGroup"] = $rightsService->isInheritSuGroup($group);
		$values["group"] = $group->getUniqueId();

        ksort($tabRights);
		$values["rights"] = $tabRights;

        $values['user'] = null;
        if($group instanceof m_users_documents_User)
        {
            $values['user'] = $group;
        }

		$this->setModel($values);
		$this->setView('success');
	}	
	
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("backoffice_accessBo","rights_Show"));
	}
}